package com.ruoyi.fjtseac.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.fjtseac.service.PhotoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 图片Controller
 *
 * @author icyrain11
 * @date 2023-06-29
 */
@Controller
@RequestMapping("/photo")
@Api(tags={"图片接口"})
public class PhotoController extends BaseController {

    private PhotoService photoService;
    @Autowired
    public PhotoController(PhotoService photoService) {
        this.photoService = photoService;
    }

    /**
     * 添加图片
     *
     * @param  file
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('fjtseac:photo:add')")
    @PostMapping(value = "/uploadPhoto")
    @ResponseBody
    @ApiOperation(value = "图片上传文件")
    public AjaxResult uploadPhoto(@Validated @RequestParam(value="file",required=false) @RequestPart("file") MultipartFile file, @ApiParam("图片进度唯一标识") @RequestParam String uuid) {
        return photoService.uploadPhoto(file, uuid);
    }

    @GetMapping("/progress")
    @ResponseBody
    @ApiOperation("图片上传进度")
    public AjaxResult getProgress(@ApiParam(value = "图片文件的唯一标识", required = true) String uuid) {
        return photoService.getProgress(uuid);
    }
}

